/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

/**
 * Created by yfyang on 4/12/14.
 */
define([ 'adminapp'], function ($app) {
    var movieType = {
        love : '爱情',
        kungfu : '功夫'
    }

    var movieStatus = ["过期", "正在热映", "即将上映"];

    // nav menu
    $app.navactive('movie_info');

    var action_tpl = Handlebars.compile($(g.actiontpl).html());
    var cover_tpl = Handlebars.compile($(g.covertpl).html());

    var $listtable = $app.listtable({
        'sAjaxSource' : g.ctx + "admin/movie/info/list",
        'fnServerParams': function( aoData){
            var sd = $('#search_form').serializeJSON();
            $.each(sd, function(name, val){
                aoData.push({"name": name, "value": val});
            });
        },
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'name' },
            {'mDataProp': 'showtimes' },
            {'mDataProp': 'states' },
            {'mDataProp': 'cover' }
        ],
        'aoColumnDefs': [
            {
                'aTargets' : [4],
                'mData'    : null,
                "bSortable": false,
                'mRender'  : function (data, type, full) {
                    var states = full["states"];
                    return movieStatus[states]
                }
            },
            {
                'aTargets' : [5],
                'mData'    : null,
                "bSortable": false,
                'mRender'  : function (data, type, full) {
                    var cover = full.cover;
                    var thumbnail = cover;
                    if (cover) {
                        thumbnail = cover.replace('.', '.thumbnail.');
                    }
                    var context = {'cover' : cover, 'thumbnail' : thumbnail};
                    /*if (full.img) {
                     full.img = full.img.replace('.', '.thumbnail.')
                     }*/
                    //console.log(full.img);
                    return cover_tpl(context);
                }
            },

            {
                'aTargets' : [6],
                'mData'    : null,
                "bSortable": false,
                'mRender'  : function (data, type, full) {
                    return action_tpl(full);
                }
            }
        ]
    }, 'movie-list');

    $('#search_btn').on('click', function (e) {
        e.preventDefault();
        $listtable.fnReloadAjax();
    });
    return {};
});